Page({
  data: {
    avatarUrl: 'https://ts4.cn.mm.bing.net/th?id=OIP-C.avAmzcmhc--litsBLiIkWAHaHa&w=249&h=250&c=8&rs=1&qlt=90&o=6&dpr=1.3&pid=3.1&rm=2',
    initurl:'https://ts4.cn.mm.bing.net/th?id=OIP-C.avAmzcmhc--litsBLiIkWAHaHa&w=249&h=250&c=8&rs=1&qlt=90&o=6&dpr=1.3&pid=3.1&rm=2',
    initname:'请点击登录',
    name: '请点击登录',
    m: "0",
    myurl:['../myorder/myorder','../changeinf/index','../about/about'],
    mySet: [{
        'id':0,
        'name': "我的预约",
        'img': "/pages/images/预约.png"
      },
      {
        'id':1,
        'name': "补全个人信息",
        'img': "/pages/images/个人信息.png"
      },
      {
        'id':2, 
        'name': "关于",
        'img': "/pages/images/关于_o.png"
      },
    ]
  },



  getUserProfile: function () {
    var that = this;
    if (this.data.m == 0) {
      wx.getUserProfile({
        desc: '信息仅作为个人展示',
        success: (res) => {
          wx.setStorage({
            data: res.userInfo,
            key: 'userInfo',
            success() {
              wx.getStorage({
                key: "userInfo",
                success(res) {
                  //console.log(res);
                  wx.cloud.callFunction({
                    name:'addopenid',
                    data:{
                      message:'addopenid',
                    }
                  }).then(res=>{
                    var app = getApp();
                    app.globalData.useropenid = res.result.openid;
                    //console.log(app.globalData.useropenid);
                  });
                  var app = getApp();
                  app.globalData.avatarUrl = res.data.avatarUrl;
                  app.globalData.name = res.data.nickName;
                  app.globalData.hasLogin = true;
                  that.setData({
                    avatarUrl: app.globalData.avatarUrl,
                    name: app.globalData.name,
                  })
                }
              })
            },
          });
          this.setData({
            m: 1
          })
        },
        fail() {
          wx.showToast({
            title: '登录失败',
            icon:"error"
          })
        }
      })
    }
  },
  exit:function(){
    var that = this;
    wx.showModal({
      title: '提示',
      content: '您确定要退出登录吗',
      success: function (res) {
        if (res.confirm) {//这里是点击了确定以后
          wx.setStorageSync('token', '');//将token置空
          var app = getApp();
          app.globalData.avatarUrl = that.data.initurl;
          app.globalData.name = that.data.initname;
          app.globalData.hasLogin = false;
          that.setData({
            avatarUrl: app.globalData.avatarUrl,
            name: app.globalData.name,
            m: "0"
          })
          wx.showToast({
            title: '退出成功',
            icon:"none"
          })
        } else {//这里是点击了取消以后
          wx.showToast({
            title: '已取消',
            icon:"none"
          })  
        }
      }
    })
  }, 
})
